#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setCursor(Qt::BlankCursor);//隐藏鼠标指针

    /******init config********/
    init_config();
    video_refresh_rate = settings->value("MONITOR/video_refresh_rate", 50).toInt();

    /******init video**************/
    video_init();
}

MainWindow::~MainWindow()
{
    delete settings;
    delete video_buffer;
    delete video_rgbbuf;
    delete video_v4l2;
    delete video_timer;
    delete ui;
}

void MainWindow::on_pushButton_close_clicked()
{
    video_stop();
    this->close();
}

void MainWindow::init_config()
{
    /*init config file*/
    QString iniFilePath = QCoreApplication::applicationDirPath() + "/config.ini";
    if(!QFile(iniFilePath).exists())
    {
        QMessageBox::critical(nullptr, "ERROR",
                              iniFilePath + " is not exist.");
        qCritical() << iniFilePath + " is not exist.";
    }
    settings = new QSettings(iniFilePath, QSettings::IniFormat);
    settings->setIniCodec("UTF-8");
}
